//
//  BookInfoSearchCell.m
//  EbookOnline
//
//  Created by mac on 15/4/16.
//  Copyright (c) 2015年 mac. All rights reserved.
//

#import "BookInfoSearchCell.h"

@interface BookInfoSearchCell ()<UISearchBarDelegate>

@property (nonatomic,strong)HMUITapbarView *tab;
@property (nonatomic,strong)UISearchBar *searchBar;

@end

@implementation BookInfoSearchCell


- (instancetype)initWithFrame:(CGRect)frame{
    self = [super initWithFrame:frame];
    if (self) {

        [self tab];

    }
    return self;
}

- (UISearchBar *)searchBar{
    if (_searchBar==nil) {
        _searchBar = [[UISearchBar alloc]init];
        _searchBar.placeholder = @"编辑";
        _searchBar.delegate = self;
        [_searchBar clearBackBar];
        
    }
    return _searchBar;
}

- (HMUITapbarView *)tab{
    if (_tab==nil) {
        _tab = [[HMUITapbarView alloc]initWithFrame:self.bounds];
        _tab.barStyle = UITapbarStyleCanFlexible;
        _tab.indentation = 10;
        _tab.tail = 10;
        _tab.eventReceiver = self;
        [self addSubview:_tab];
        [_tab mas_makeConstraints:^(MASConstraintMaker *make) {
            make.top.mas_equalTo(self.mas_top).offset(0);
            make.left.mas_equalTo(self.mas_left).offset(0);
            make.height.mas_equalTo(40);
            make.right.mas_equalTo(self.mas_right).offset(0);
        }];
        
        UIButten * btn = [_tab addItemWithTitle:@"编辑" imageName:@"back.png" size:CGSizeMake(40, 40) background:YES] ;
        [btn setTitleColor:RGB(1, 1, 1) forState:UIControlStateNormal];
        [btn setTitleColor:RGB(0.5, 0.5, 0.5) forState:UIControlStateSelected];
        btn.buttenType = UIButtenTypeAutoSelect;
        [btn setTitle:@"取消" forState:UIControlStateSelected];
        btn.titleLabel.font = [UIFont systemFontOfSize:14];
//        btn.imageSize = CGSizeZero;
        [_tab addFlexible];
    
        [_tab addContentView:self.searchBar size:CGSizeMake(self.width-20-40-66, self.height)];
        [_tab addFlexible];
        [_tab addItemWithTitle:nil imageName:@"back.png" size:CGSizeMake(33, 40)].tagString = @"shitu";
        [_tab addItemWithTitle:nil imageName:@"back.png" size:CGSizeMake(33, 40)].tagString = @"liebiao";
        [_tab setSelectedIndex:2 witoutSignal:NO];
    }
    return _tab;
}

- (BOOL)searchBarShouldBeginEditing:(UISearchBar *)searchBar{

    if (self.delegate) {
        [self.delegate bookInfoSearchCellTouch:1];
    }
    return NO;
}

ON_TapBar(signal){
    if ([signal is:[HMUITapbarView TAPNOSELECTED]]) {
        if (_tab.selectedIndex==0) {
            [signal returnYES];
        }else{
            [signal returnNO];
        }
        
    }else if ([signal is:[HMUITapbarView TAPCHANGED]]){
        if (self.delegate) {
            [self.delegate bookInfoSearchCellTouch:_tab.selectedIndex];
        }
    }
}

@end
